home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Suzy B Software 2
/
Suzy B Software CD-ROM 2 (1994).iso
/
extras
/
programm
/
mcode_01
/
source
/
function.s
next >
Wrap
Text File
|
1995-04-27
|
5KB
|
132 lines
* Program : The is a general collection of the functions that
* are used most of the time
* Author : Stephen McNabb
* Creation date : 15th February 1995
* Last update : 15th February 1995
* Parameters : Different for each function
* Output : Different for each function
* Comment : This source code file takes some of the functions
* from '\source\basic\' and puts them to use. See
* the appropriate function in this directory for
* parameters and outputs
*
* exit - uses 'exit.s'
* cls - uses 'putchar.s' and escape sequences
* gchar - uses 'getchar1.s'
* pchar - uses 'putchar.s'
* ptext - uses 'puttext.s'
* line - uses 'puttext.s'
* wait - uses 'getchar2.s'
*
* This is a handy file to include with each of your
* own programs. You will notice that on most of the
* functions the data and address registers are pushed
* onto the stack at the beginning of the routine and
* popped back off at the end. This is because the trap
* functions use the registers themselves and your own
* data in the registers could become corrupt if you
* don't save them before performing a trap.
* This routine displays a 'Press a key' on the screen and waits
* for a keypress before exiting cleanly from the program
exit: bsr wait /wait for a keypress
move.w #0,-(sp) /move exit code to stack
move.w #$4c,-(sp) /use Pterm() function
trap #1 /use gemdos
* This routine clears the screen and places the cursor at the top
* left hand side of the screen. It uses the ESC E sequence
cls: movem.l d0,-(sp) /stack register
move.b #27,d0 /move escape character to d0
jsr pchar /and display on screen
move.b #'E',d0 /move 'E' character to d0
jsr pchar /and display on screen
movem.l (sp)+,d0 /unstack register
rts /return from subroutine
* This routine gets a character from the keyboard and stores
* the result in d0
gchar: movem.l d1-d2/a0-a2,-(sp) /stack registers
move.w #1,-(sp) /use Cconin() function
trap #1 /use gemdos
addq.l #2,sp /tidy up stack
movem.l (sp)+,d1-d2/a0-a2 /unstack registers
rts /return from subroutine
* This routine gets a string of characters from the keyboard and
* stores the address of the string in d0
gtext: movem.l d1-d2/a0-a2,-(sp) /stack registers
move.l #length,-(sp) /move length of string onto stack
move.w #$A,-(sp) /use Cconrs() function
trap #1 /use gemdos
addq.l #6,sp /tidy up stack
move.l #string,d0 /load address of string into d0
movem.l (sp)+,d1-d2/a0-a2 /unstack registers
rts /return from subroutine
* This routine displays a character stored in d0 on the screen
pchar: movem.l d0-d2/a0-a2,-(sp) /stack regi|sters
move.w d0,-(sp) /move character in d0 onto stack
move.w #2,-(sp) /use Cconout() function
trap #1 /use gemdos
addq.l #4,sp /tidy up stack
movem.l (sp)+,d0-d2/a0-a2 /unstack registers
rts /return from subroutine
* This routine displays a null terminated string on the screen.
* The address of the string must be stored in d0 before using it.
ptext: movem.l d0-d2/a0-a2,-(sp) /stack regsiters
move.l d0,-(sp) /move address of string to stack
move.w #$9,-(sp) /use Cconws() function
trap #1 /use gemdos
addq.l #6,sp /tidy up stack
movem.l (sp)+,d0-d2/a0-a2 /unstack registers
rts /return from subroutine
* This routine displays a carriage return and line feed to the screen
line: movem.l d0,-(sp) /stack register
move.l #cr,d0 /move carriage return to d0
jsr ptext /and display on screen
movem.l (sp)+,d0 /unstack register
rts /return from subroutine
* This routine displays a 'Press a key.' message on the screen
* and waits for a keypress which is not echoed to the screen
wait: movem.l d0-d2/a0-a2,-(sp) /stack registers
move.l #press,d0 /move 'press-a-key' string to stack
jsr ptext /and display on screen
move.w #7,-(sp) /use Crawcin() function
trap #1 /use gemdos
addq.l #2,sp /tidy up stack
movem.l (sp)+,d0-d2/a0-a2 /unstack registers
rts /return from subroutine
*** Program Data ***
length: dc.b 80 /length of string to be read -+
read: dc.b 0 /length of string actually read | keep together
string: ds.b 81 /string read -+
press: dc.b $D,$A,'Press a key',$D,$A,0 /'Press a key' string
cr: dc.b $D,$A,0 /carriage return and line feed
* Note : $D = Carriage return
* $A = Line feed
*** End of file ***